package com.szxy.miaosha.service.impl;

import com.szxy.miaosha.dao.OrderInfoDao;
import com.szxy.miaosha.domain.OrderInfo;
import com.szxy.miaosha.exception.GlobalException;
import com.szxy.miaosha.service.OrderInfoService;
import com.szxy.miaosha.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Author: zwz
 * @Date:2020/9/9 21:51
 * @Description:com.szxy.miaosha.service.impl
 * @Version:1.0
 **/
@Service
public class OrderInfoServiceImpl implements OrderInfoService {

    @Autowired
    private OrderInfoDao orderInfoDao;

    @Override
    @Transactional(rollbackFor = GlobalException.class)
    public OrderInfo insertOrder(GoodsVo goodsVo, Long userId) {
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setUserId(userId);
        orderInfo.setGoodsId(goodsVo.getId());
        orderInfo.setGoodsName(goodsVo.getGoodsName());
        orderInfo.setGoodsPrice(goodsVo.getMiaoshaPrice());
        orderInfo.setDeliveryAddrId(0L);
        orderInfo.setGoodsCount(1);
        orderInfo.setStatus(0);
        orderInfo.setOrderChannel(0);
        orderInfo.setCreateDate(new Date());
        //  插入订单详情
        Long orderId = orderInfoDao.insertOrderInfo(orderInfo);
        orderInfo.setId(orderId);
        return orderInfo;
    }
}
